package cn.crm.controller;

import cn.crm.pojo.Users;
import cn.crm.service.UsersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping("/users")
public class UsersController {

    @Resource
    private UsersService usersService;

    @RequestMapping(value = "/login",method=RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> login(@RequestBody Users users){
        Users list= usersService.login(users);
        Map<String,Object> map = new HashMap<>();
        if (list != null) {
            map.put("msg","成功");
            map.put("success",true);
            map.put("list",list);
        }else {
            map.put("msg","失败");
        }
        return map;
    }

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> register(@RequestBody Users users){
        Integer register = usersService.register(users);
        Map<String,Object> map1 = new HashMap<>();
        if (register<0) {
            map1.put("msg", "失败");
            map1.put("success", false);
        }else {
            map1.put("msg","成功");
            map1.put("success",true);
        }
        return map1;
    }
}

